{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "Ou_oQJBrRxsA"
   },
   "source": [
    "# Get Started with Earth Engine\n",
    "\n",
    "This Get Started guide is intended as a quick way to start programming with the Earth Engine Python API. For an introductory look at Python and more in-depth exercises with the Earth Engine API, see the [tutorials](https://github.com/giswqs/earthengine-py-notebooks). For suggestions on Python coding style, see the [Google Python Style Guide](http://google.github.io/styleguide/pyguide.html).[link text](https://)\n",
    "\n",
    "Google Earth Engine allows users to run algorithms on georeferenced imagery and vectors stored on Google's infrastructure. The Google Earth Engine API provides a library of functions which may be applied to data for display and analysis. Earth Engine's [public data catalog](https://developers.google.com/earth-engine/datasets/) contains a large amount of publicly available imagery and vector datasets. Private assets can also be created in users' personal folders.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "HAXUSh3jaRCt"
   },
   "source": [
    "## Installing the Earth Engine API"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "KhWWe9Y-TAzZ"
   },
   "outputs": [],
   "source": [
    "import subprocess\n",
    "\n",
    "try:\n",
    "    import geehydro\n",
    "except ImportError:\n",
    "    print('geehydro package not installed. Installing ...')\n",
    "    subprocess.check_call([\"python\", '-m', 'pip', 'install', 'geehydro'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "OGUbVwc9a31e"
   },
   "source": [
    "Import libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "qbDHk-B3a9K2"
   },
   "outputs": [],
   "source": [
    "import ee\n",
    "import folium\n",
    "import geehydro"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "f8jXYIUcbEJd"
   },
   "source": [
    "Authenticate and initialize Earth Engine API. You only need to authenticate the Earth Engine API once. Uncomment the line `ee.Authenticate()` \n",
    "if you are running this notebook for this first time or if you are getting an authentication error.  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "wBgIAFCsbB1Y"
   },
   "outputs": [],
   "source": [
    "# ee.Authenticate()\n",
    "ee.Initialize()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "XiacQTXbZvwK"
   },
   "source": [
    "## ‘Hello world!’\n",
    "Printing out information to the console is a basic task for getting information about an object, displaying the numeric result of a computation, displaying object metadata or helping with debugging. The iconic ‘Hello World!’ example is:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 9005,
     "status": "ok",
     "timestamp": 1580323485429,
     "user": {
      "displayName": "Qiusheng Wu",
      "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mClnrRJt-9CiCsZmUOfCdngabcoPR4UAFqqj1vY=s64",
      "userId": "16932034244543127511"
     },
     "user_tz": 300
    },
    "id": "kEihQHMfZpTR",
    "outputId": "52b2f20c-4782-47ab-f1e5-dd5a0466969f"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello world!\n"
     ]
    }
   ],
   "source": [
    "# traditional python string\n",
    "print('Hello world!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 8996,
     "status": "ok",
     "timestamp": 1580323485431,
     "user": {
      "displayName": "Qiusheng Wu",
      "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mClnrRJt-9CiCsZmUOfCdngabcoPR4UAFqqj1vY=s64",
      "userId": "16932034244543127511"
     },
     "user_tz": 300
    },
    "id": "DHCA26YIaMJc",
    "outputId": "ed5a2340-f62e-4cca-aee2-5ca5ab532451"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World from Earth Engine!\n"
     ]
    }
   ],
   "source": [
    "# Earth Eninge object\n",
    "print(ee.String('Hello World from Earth Engine!').getInfo())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 54
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 9878,
     "status": "ok",
     "timestamp": 1580323486324,
     "user": {
      "displayName": "Qiusheng Wu",
      "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mClnrRJt-9CiCsZmUOfCdngabcoPR4UAFqqj1vY=s64",
      "userId": "16932034244543127511"
     },
     "user_tz": 300
    },
    "id": "nO6Usg8pZkgv",
    "outputId": "ecaca48d-3783-4f02-db76-9a5c2b3a1918"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'type': 'Image', 'bands': [{'id': 'B1', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7661, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 460785, 0, -30, 4264215]}, {'id': 'B2', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7661, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 460785, 0, -30, 4264215]}, {'id': 'B3', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7661, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 460785, 0, -30, 4264215]}, {'id': 'B4', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7661, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 460785, 0, -30, 4264215]}, {'id': 'B5', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7661, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 460785, 0, -30, 4264215]}, {'id': 'B6', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7661, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 460785, 0, -30, 4264215]}, {'id': 'B7', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7661, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 460785, 0, -30, 4264215]}, {'id': 'B8', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [15321, 15601], 'crs': 'EPSG:32610', 'crs_transform': [15, 0, 460792.5, 0, -15, 4264207.5]}, {'id': 'B9', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7661, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 460785, 0, -30, 4264215]}, {'id': 'B10', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7661, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 460785, 0, -30, 4264215]}, {'id': 'B11', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7661, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 460785, 0, -30, 4264215]}, {'id': 'BQA', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7661, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 460785, 0, -30, 4264215]}], 'id': 'LANDSAT/LC08/C01/T1/LC08_044034_20140318', 'version': 1497472259022000.0, 'properties': {'RADIANCE_MULT_BAND_5': 0.006170900072902441, 'RADIANCE_MULT_BAND_6': 0.001534600043669343, 'RADIANCE_MULT_BAND_3': 0.011958000250160694, 'RADIANCE_MULT_BAND_4': 0.010084000416100025, 'RADIANCE_MULT_BAND_1': 0.012672999873757362, 'RADIANCE_MULT_BAND_2': 0.012977000325918198, 'K2_CONSTANT_BAND_11': 1201.1441650390625, 'K2_CONSTANT_BAND_10': 1321.078857421875, 'system:footprint': {'type': 'LinearRing', 'coordinates': [[-121.3637119499993, 36.41016684133052], [-121.35905784815819, 36.42528989660049], [-121.2315833015866, 36.840374852891664], [-121.09978718573184, 37.26438246506325], [-121.00571062336425, 37.564795515259384], [-120.98453376062118, 37.632161601008896], [-120.95100979452299, 37.73864548098522], [-120.90277241165228, 37.89149086576169], [-120.8836409072059, 37.951976016520376], [-120.85713152433351, 38.03584247073611], [-120.82804345546616, 38.12789513604401], [-122.38148159443172, 38.42337450676813], [-122.9500220192271, 38.525813632077686], [-122.95103687833704, 38.52422133103557], [-122.9569591344694, 38.504384836247866], [-123.43853932998316, 36.805122381748035], [-123.18722447462653, 36.759167415189125], [-121.5105534682754, 36.43765126135182], [-121.36447385999617, 36.408418528930035], [-121.3637119499993, 36.41016684133052]]}, 'REFLECTIVE_SAMPLES': 7661, 'SUN_AZIMUTH': 146.2395782470703, 'CPF_NAME': 'LC08CPF_20140101_20140331_01.01', 'DATE_ACQUIRED': '2014-03-18', 'ELLIPSOID': 'WGS84', 'google:registration_offset_x': 0, 'google:registration_offset_y': 0, 'STATION_ID': 'LGN', 'RESAMPLING_OPTION': 'CUBIC_CONVOLUTION', 'ORIENTATION': 'NORTH_UP', 'WRS_ROW': 34, 'RADIANCE_MULT_BAND_9': 0.0024117000866681337, 'TARGET_WRS_ROW': 34, 'RADIANCE_MULT_BAND_7': 0.0005172499804757535, 'RADIANCE_MULT_BAND_8': 0.0114120002835989, 'IMAGE_QUALITY_TIRS': 9, 'TRUNCATION_OLI': 'UPPER', 'CLOUD_COVER': 0.05999999865889549, 'GEOMETRIC_RMSE_VERIFY': 3.249000072479248, 'COLLECTION_CATEGORY': 'T1', 'GRID_CELL_SIZE_REFLECTIVE': 30, 'CLOUD_COVER_LAND': 0.10000000149011612, 'GEOMETRIC_RMSE_MODEL': 6.78000020980835, 'COLLECTION_NUMBER': 1, 'IMAGE_QUALITY_OLI': 9, 'LANDSAT_SCENE_ID': 'LC80440342014077LGN01', 'WRS_PATH': 44, 'google:registration_count': 0, 'PANCHROMATIC_SAMPLES': 15321, 'PANCHROMATIC_LINES': 15601, 'GEOMETRIC_RMSE_MODEL_Y': 4.747000217437744, 'REFLECTIVE_LINES': 7801, 'TIRS_STRAY_LIGHT_CORRECTION_SOURCE': 'TIRS', 'GEOMETRIC_RMSE_MODEL_X': 4.841000080108643, 'system:asset_size': 1105511852, 'system:index': 'LC08_044034_20140318', 'REFLECTANCE_ADD_BAND_1': -0.10000000149011612, 'REFLECTANCE_ADD_BAND_2': -0.10000000149011612, 'DATUM': 'WGS84', 'REFLECTANCE_ADD_BAND_3': -0.10000000149011612, 'REFLECTANCE_ADD_BAND_4': -0.10000000149011612, 'RLUT_FILE_NAME': 'LC08RLUT_20130211_20150302_01_11.h5', 'REFLECTANCE_ADD_BAND_5': -0.10000000149011612, 'REFLECTANCE_ADD_BAND_6': -0.10000000149011612, 'REFLECTANCE_ADD_BAND_7': -0.10000000149011612, 'REFLECTANCE_ADD_BAND_8': -0.10000000149011612, 'BPF_NAME_TIRS': 'LT8BPF20140318182855_20140318190505.01', 'GROUND_CONTROL_POINTS_VERSION': 4, 'DATA_TYPE': 'L1TP', 'UTM_ZONE': 10, 'LANDSAT_PRODUCT_ID': 'LC08_L1TP_044034_20140318_20170307_01_T1', 'REFLECTANCE_ADD_BAND_9': -0.10000000149011612, 'google:registration_ratio': 0, 'GRID_CELL_SIZE_PANCHROMATIC': 15, 'RADIANCE_ADD_BAND_4': -50.419559478759766, 'REFLECTANCE_MULT_BAND_7': 1.9999999494757503e-05, 'system:time_start': 1395168392050, 'RADIANCE_ADD_BAND_5': -30.854249954223633, 'REFLECTANCE_MULT_BAND_6': 1.9999999494757503e-05, 'RADIANCE_ADD_BAND_6': -7.67317008972168, 'REFLECTANCE_MULT_BAND_9': 1.9999999494757503e-05, 'PROCESSING_SOFTWARE_VERSION': 'LPGS_2.7.0', 'RADIANCE_ADD_BAND_7': -2.5862700939178467, 'REFLECTANCE_MULT_BAND_8': 1.9999999494757503e-05, 'RADIANCE_ADD_BAND_1': -63.364051818847656, 'RADIANCE_ADD_BAND_2': -64.88555908203125, 'RADIANCE_ADD_BAND_3': -59.79148864746094, 'REFLECTANCE_MULT_BAND_1': 1.9999999494757503e-05, 'RADIANCE_ADD_BAND_8': -57.06106185913086, 'REFLECTANCE_MULT_BAND_3': 1.9999999494757503e-05, 'RADIANCE_ADD_BAND_9': -12.058540344238281, 'REFLECTANCE_MULT_BAND_2': 1.9999999494757503e-05, 'REFLECTANCE_MULT_BAND_5': 1.9999999494757503e-05, 'REFLECTANCE_MULT_BAND_4': 1.9999999494757503e-05, 'THERMAL_LINES': 7801, 'TIRS_SSM_POSITION_STATUS': 'NOMINAL', 'GRID_CELL_SIZE_THERMAL': 30, 'NADIR_OFFNADIR': 'NADIR', 'RADIANCE_ADD_BAND_11': 0.10000000149011612, 'REQUEST_ID': '0501703063989_00019', 'EARTH_SUN_DISTANCE': 0.9953709244728088, 'TIRS_SSM_MODEL': 'ACTUAL', 'FILE_DATE': 1488849349000, 'SCENE_CENTER_TIME': '18:46:32.0535800Z', 'SUN_ELEVATION': 46.471065521240234, 'BPF_NAME_OLI': 'LO8BPF20140318183249_20140318190412.01', 'RADIANCE_ADD_BAND_10': 0.10000000149011612, 'ROLL_ANGLE': -0.0010000000474974513, 'K1_CONSTANT_BAND_10': 774.8853149414062, 'SATURATION_BAND_1': 'Y', 'SATURATION_BAND_2': 'Y', 'SATURATION_BAND_3': 'Y', 'SATURATION_BAND_4': 'Y', 'SATURATION_BAND_5': 'Y', 'MAP_PROJECTION': 'UTM', 'SATURATION_BAND_6': 'Y', 'SENSOR_ID': 'OLI_TIRS', 'SATURATION_BAND_7': 'Y', 'K1_CONSTANT_BAND_11': 480.8883056640625, 'SATURATION_BAND_8': 'N', 'SATURATION_BAND_9': 'N', 'TARGET_WRS_PATH': 44, 'RADIANCE_MULT_BAND_11': 0.00033420001273043454, 'RADIANCE_MULT_BAND_10': 0.00033420001273043454, 'GROUND_CONTROL_POINTS_MODEL': 527, 'SPACECRAFT_ID': 'LANDSAT_8', 'ELEVATION_SOURCE': 'GLS2000', 'THERMAL_SAMPLES': 7661, 'GROUND_CONTROL_POINTS_VERIFY': 164}}\n"
     ]
    }
   ],
   "source": [
    "print(ee.Image('LANDSAT/LC08/C01/T1/LC08_044034_20140318').getInfo())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "UOiWRQ3NcVO4"
   },
   "source": [
    "## Create an interactive map \n",
    "This step creates an interactive map using [folium](https://github.com/python-visualization/folium). The default basemap is the OpenStreetMap. Additional basemaps can be added using the `Map.setOptions()` function. \n",
    "The optional basemaps can be `ROADMAP`, `SATELLITE`, `HYBRID`, `TERRAIN`, or `ESRI`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "oVI0eKCqcWHQ"
   },
   "outputs": [],
   "source": [
    "Map = folium.Map(location=[40, -100], zoom_start=4)\n",
    "Map.setOptions('HYBRID')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "4jvERCGPb-fp"
   },
   "source": [
    "## Adding data to the map\n",
    "In addition to printing information to the console, adding data to the Map is the way to visualize geographic data. Use Map.addLayer() to do that. In the following example, an Image is instantiated (how to find these images is covered later) using ee.Image(), added to the map with Map.addLayer() and the map is centered over the image:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "VSLLC2SdZh_W"
   },
   "outputs": [],
   "source": [
    "# Load an image.\n",
    "image = ee.Image('LANDSAT/LC08/C01/T1/LC08_044034_20140318')\n",
    "\n",
    "# Center the map on the image.\n",
    "Map.centerObject(image, 9)\n",
    "\n",
    "# Display the image.\n",
    "Map.addLayer(image, {}, 'Landsat 8 original image')\n",
    "\n",
    "# Define visualization parameters in an object literal.\n",
    "vizParams = {'bands': ['B5', 'B4', 'B3'],\n",
    "             'min': 5000, 'max': 15000, 'gamma': 1.3}\n",
    "\n",
    "# Center the map on the image and display.\n",
    "Map.centerObject(image, 9)\n",
    "Map.addLayer(image, vizParams, 'Landsat 8 False color')\n",
    "\n",
    "# Use Map.addLayer() to add features and feature collections to the map. For example,\n",
    "counties = ee.FeatureCollection('TIGER/2016/Counties')\n",
    "Map.addLayer(counties, {}, 'counties')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "RzbPdNnuchJL"
   },
   "source": [
    "## Display Earth Engine data layers "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 907
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 12037,
     "status": "ok",
     "timestamp": 1580323488511,
     "user": {
      "displayName": "Qiusheng Wu",
      "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mClnrRJt-9CiCsZmUOfCdngabcoPR4UAFqqj1vY=s64",
      "userId": "16932034244543127511"
     },
     "user_tz": 300
    },
    "id": "eXBlZDmvch5u",
    "outputId": "e456cc78-21f4-43d1-b4d3-850884ed07ef"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgCiAgICAgICAgPHNjcmlwdD4KICAgICAgICAgICAgTF9OT19UT1VDSCA9IGZhbHNlOwogICAgICAgICAgICBMX0RJU0FCTEVfM0QgPSBmYWxzZTsKICAgICAgICA8L3Njc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AgICAgICAgICB9CiAgICAgICAgICAgIDwvc3R5bGU+CiAgICAgICAgCiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvbGVhZmxldC5mdWxsc2NyZWVuLzEuNC4yL0NvbnRyb2wuRnVsbFNjcmVlbi5taW4uanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2NkbmpzLmNsb3VkZmxhcmUuY29tL2FqYXgvbGlicy9sZWFmbGV0LmZ1bGxzY3JlZW4vMS40LjIvQ29udHJvbC5GdWxsU2NyZWVuLm1pbi5jc3MiLz4KPC9oZWFkPgo8Ym9keT4gICAgCiAgICAKICAgICAgICAgICAgPGRpdiBjbGFzcz0iZm9saXVtLW1hcCIgaWQ9Im1hcF9jMmNjMDg4NTkwMjM0NWE5YTUwMWRmMTY1YzhjNWY0YyIgPjwvZGl2PgogICAgICAgIAo8L2JvZHk+CjxzY3JpcHQ+ICAgIAogICAgCiAgICAgICAgICAgIHZhciBtYXBfYzJjYzA4ODU5MDIzNDVhOWE1MDFkZjE2NWM4YzVmNGMgPSBMLm1hcCgKICAgICAgICAgICAgICAgICJtYXBfYzJjYzA4ODU5MDIzNDVhOWE1MDFkZjE2NWM4YzVmNGMiLAogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGNlbnRlcjogWzQwLjAsIC0xMDAuMF0sCiAgICAgICAgICAgICAgICAgICAgY3JzOiBMLkNSUy5FUFNHMzg1NywKICAgICAgICAgICAgICAgICAgICB6b29tOiA0LAogICAgICAgICAgICAgICAgICAgIHpvb21Db250cm9sOiB0cnVlLAogICAgICAgICAgICAgICAgICAgIHByZWZlckNhbnZhczogZmFsc2UsCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICk7CgogICAgICAgICAgICAKCiAgICAgICAgCiAgICAKICAgICAgICAgICAgdmFyIHRpbGVfbGF5ZXJfMG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ICAgICAgICAgICAgIHZhciBsYXRfbG5nX3BvcHVwX2NlMjg2YWEwN2U2ZjQ4ZGViNGE4YTc5OGFmNjdiYzkxID0gTC5wb3B1cCgpOwogICAgICAgICAgICAgICAgZnVuY3Rpb24gbGF0TG5nUG9wKGUpIHsKICAgICAgICAgICAgICAgICAgICBsYXRfbG5nX3BvcHVwX2NlMjg2YWEwN2U2ZjQ4ZGViNGE4YTc5OGFmNjdiYzkxCiAgICAgICAgICAgICAgICAgICAgICAgIC5zZXRMYXRMbmcoZS5sYXRsbmcpCiAgICAgICAgICAgICAgICAgICAgICAgIC5zZXRDb250ZW50KCJMYXRpdHVkZTogIiArIGUubGF0bG5nLmxhdC50b0ZpeGVkKDQpICsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIjxicj5Mb25naXR1ZGU6ICIgKyBlLmxhdGxuZy5sbmcudG9GaXhlZCg0KSkKICAgICAgICAgICAgICAgICAgICAgICAgLm9wZW5PbihtYXBfYzJjYzA4ODU5MDIzNDVhOWE1MDFkZjE2NWM4YzVmNGMpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIG1hcF9jMmNjMDg4NTkwMjM0NWE5YTUwMWRmMTY1YzhjNWY0Yy5vbignY2xpY2snLCBsYXRMbmdQb3ApOwogICAgICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7f64c0ec2be0>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Map.setControlVisibility(layerControl=True, fullscreenControl=True, latLngPopup=True)\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "jY4r9oFjdt8G"
   },
   "source": [
    "## Finding images, image collections and feature collections\n",
    "Images, image collections, and feature collections are discoverable by searching the Earth Engine Data Catalog. For example, entering ‘Landsat 8’ into the search field results in a list of raster datasets. (The complete listing of Earth Engine datasets is at the [Earth Engine Data Catalog](https://developers.google.com/earth-engine/datasets)). Click on the dataset name to get a brief description, information about the temporal availability, data provider and collection ID. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 907
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 14568,
     "status": "ok",
     "timestamp": 1580323491057,
     "user": {
      "displayName": "Qiusheng Wu",
      "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mClnrRJt-9CiCsZmUOfCdngabcoPR4UAFqqj1vY=s64",
      "userId": "16932034244543127511"
     },
     "user_tz": 300
    },
    "id": "PIxWBP2MS_lU",
    "outputId": "2c5456e2-19a7-45ae-886a-85b756fc0a61"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgCiAgICAgICAgPHNjcmlwdD4KICAgICAgICAgICAgTF9OT19UT1VDSCA9IGZhbHNlOwogICAgICAgICAgICBMX0RJU0FCTEVfM0QgPSBmYWxzZTsKICAgICAgICA8L3NjcmlwdD4KICAgIAogICAgPHNjcmlwdCBzcmM9Imh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vbGVhZmxldEAxLjUuMS9kaXN0L2xlYWZsZXQuanMiPjwvc2NyaXB0PgogICAgPHNjcmlwdCBzcmM9Imh0dHBzOi8vY29kZS5qcXVlcnkuY29tL2pxdWVyeS0xLjEyLjQubWluLmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3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V0IiBocmVmPSJodHRwczovL2NkbmpzLmNsb3VkZmxhcmUuY29tL2FqYXgvbGlicy9sZWFmbGV0LmZ1bGxzY3JlZW4vMS40LjIvQ29udHJvbC5GdWxsU2NyZWVuLm1pbi5jc3MiLz4KPC9oZWFkPgo8Ym9keT4gICAgCiAgICAKICAgICAgICAgICAgPGRpdiBjbGFzcz0iZm9saXVtLW1hcCIgaWQ9Im1hcF82NDNkMTk4NTAzNDM0Nzk5YmNjZDQ4ZmU1OGUzNDZhZiIgPjwvZGl2PgogICAgICAgIAo8L2JvZHk+CjxzY3JpcHQ+ICAgIAogICAgCiAgICAgICAgICAgIHZhciBtYXBfNjQzZDE5ODUwMzQzNDc5OWJjY2Q0OGZlNThlMzQ2YWYgPSBMLm1hcCgKICAgICAgICAgICAgICAgICJtYXBfNjQzZDE5ODUwMzQzNDc5OWJjY2Q0OGZlNThlMzQ2YWYiLAogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGNlbnRlcjogWzQwLjAsIC0xMDAuMF0sCiAgICAgICAgICAgICAgICAgICAgY3JzOiBMLkNSUy5FUFNHMzg1NywKICAgICAgICAgICAgICAgICAgICB6b29tOiA0LAogICAgICAgICAgICAgICAgICAgIHpvb21Db250cm9sOiB0cnVlLAogICAgICAgICAgICAgICAgICAgIHByZWZlckNhbnZhczogZmFsc2UsCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICk7CgogICAgICAgICAgICAKCiAgICAgICAgCiAgICAKICAgICAgICAgICAgdmFyIHRpbGVfbGF5ZXJfYjg3YzgzODQ3YmIwNDdlMGJlMzJmZjdlZGZjNzZmOTEgPSBMLnRpbGVMYXllcigKICAgICAgICAgICAgICAgICJodHRwczovL3tzfS50aWxlLm9wZW5zdHJlZXRtYXAub3JnL3t6fS97eH0ve3l9LnBuZyIsCiAgICAgICAgICAgICAgICB7ImF0dHJpYnV0aW9uIjogIkRhdGEgYnkgXHUwMDI2Y29weTsgXHUwMDNjYSBocmVmPVwiaH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jogZmFsc2V9CiAgICAgICAgICAgICkuYWRkVG8obWFwXzY0M2QxOTg1MDM0MzQ3OTliY2NkNDhmZTU4ZTM0NmFmKTsKICAgICAgICAKICAgIAogICAgICAgICAgICB2YXIgbGF5ZXJfY29udHJvbF9iOTY5ZjU3MjM4Mzk0MDFmODIzY2ZiMjUzNTUxZjExYyA9IHsKICAgICAgICAgICAgICAgIGJhc2VfbGF5ZXJzIDogewogICAgICAgICAgICAgICAgICAgICJvcGVuc3RyZWV0bWFwIiA6IHRpbGVfbGF5ZXJfYjg3YzgzODQ3YmIwNDdlMGJlMzJmZjdlZGZjNzZmOTEsCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgb3ZlcmxheXMgOiAgewogICAgICAgICAgICAgICAgICAgICJHb29nbGUgU2F0ZWxsaXRlIiA6IHRpbGVfbGF5ZXJfMWE5YTNmMmM1Yjc5NDE4OWFmMmU3MDE4MzVhNmNmMTMsCiAgICAgICAgICAgICAgICAgICAgIkxhbmRzYXQgOCBpbWFnZSIgOiB0aWxlX2xheWVyX2EyZGExMzMyMDc2MDQyY2RhYjk2ZTBhYmM2YjZmOTA0LAogICAgICAgICAgICAgICAgICAgICJNZWRpYW4iIDogdGlsZV9sYXllcl9kN2M3OTY4MjBjZmQ0ZDczYmM1MGY3Y2NmMGY0YTc0MywKICAgICAgICAgICAgICAgICAgICAiQ2FsaWZvcm5pYSIgOiB0aWxlX2xheWVyXzcxNzMzNWNmNDQ0MTQ2YWY5MDRmMDIzODJmNzI5YWNiLAogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgfTsKICAgICAgICAgICAgTC5jb250cm9sLmxheWVycygKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfYjk2OWY1NzIzODM5NDAxZjgyM2NmYjI1MzU1MWYxMWMuYmFzZV9sYXllcnMsCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sX2I5NjlmNTcyMzgzOTQwMWY4MjNjZmIyNTM1NTFmMTFjLm92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liY2NkNDhmZTU4ZTM0NmFmKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBtYXBfNjQzZDE5ODUwMzQzNDc5OWJjY2Q0OGZlNThlMzQ2YWYub24oJ2NsaWNrJywgbGF0TG5nUG9wKTsKICAgICAgICAgICAgCjwvc2NyaXB0Pg==\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7f64c0e46ef0>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create a map\n",
    "Map = folium.Map(location=[40, -100], zoom_start=4)\n",
    "Map.setOptions('HYBRID')\n",
    "\n",
    "# Add Earth Engine script\n",
    "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1')\n",
    "\n",
    "point = ee.Geometry.Point(-122.262, 37.8719)\n",
    "start = ee.Date('2014-06-01')\n",
    "finish = ee.Date('2014-10-01')\n",
    "\n",
    "filteredCollection = ee.ImageCollection('LANDSAT/LC08/C01/T1') \\\n",
    "    .filterBounds(point) \\\n",
    "    .filterDate(start, finish) \\\n",
    "    .sort('CLOUD_COVER', True)\n",
    "\n",
    "first = filteredCollection.first()\n",
    "# Define visualization parameters in an object literal.\n",
    "vizParams = {'bands': ['B5', 'B4', 'B3'],\n",
    "             'min': 5000, 'max': 15000, 'gamma': 1.3}\n",
    "Map.centerObject(first, 8)\n",
    "Map.addLayer(first, vizParams, 'Landsat 8 image')\n",
    "\n",
    "# Load a feature collection.\n",
    "featureCollection = ee.FeatureCollection('TIGER/2016/States')\n",
    "\n",
    "# Filter the collection.\n",
    "filteredFC = featureCollection.filter(ee.Filter.eq('NAME', 'California'))\n",
    "\n",
    "# Create a mosiac\n",
    "mosaic = ee.ImageCollection('LANDSAT/LC08/C01/T1') \\\n",
    "    .filterBounds(filteredFC) \\\n",
    "    .filterDate('2019-01-01', '2019-12-31') \\\n",
    "\n",
    "median = mosaic.median().clip(filteredFC)\n",
    "\n",
    "Map.addLayer(median, vizParams, 'Median')\n",
    "\n",
    "# Display the collection.\n",
    "Map.addLayer(filteredFC, {}, 'California')\n",
    "\n",
    "# Diplay the map\n",
    "Map.setControlVisibility(layerControl=True, fullscreenControl=True, latLngPopup=True)\n",
    "Map\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "oTBbng00hqid"
   },
   "source": [
    "## Band math\n",
    "Perform mathematical operations on images using Image methods. This may include band recombinations (spectral indices), image differencing or mathematical operations such as multiplication by a constant. For example, compute the difference between Normalized Difference Vegetation Index (NDVI) images 20 years apart:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 907
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 16161,
     "status": "ok",
     "timestamp": 1580323492667,
     "user": {
      "displayName": "Qiusheng Wu",
      "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mClnrRJt-9CiCsZmUOfCdngabcoPR4UAFqqj1vY=s64",
      "userId": "16932034244543127511"
     },
     "user_tz": 300
    },
    "id": "N6eYjSfBhxPo",
    "outputId": "bf59576b-7c9c-497b-84cc-ab9d032ee990"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgCiAgICAgICAgPHNjcmlwdD4KICAgICAgICAgICAgTF9OT19UT1VDSCA9IGZhbHNlOwogICAgICAgICAgICBMX0RJU0FCTEVfM0QgPSBmYWxzZTsKICAgICAgICA8L3NjcmlwdD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AgICB9CiAgICAgICAgICAgIDwvc3R5bGU+CiAgICAgICAgCiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvbGVhZmxldC5mdWxsc2NyZWVuLzEuNC4yL0NvbnRyb2wuRnVsbFNjcmVlbi5taW4uanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2NkbmpzLmNsb3VkZmxhcmUuY29tL2FqYXgvbGlicy9sZWFmbGV0LmZ1bGxzY3JlZW4vMS40LjIvQ29udHJvbC5GdWxsU2NyZWVuLm1pbi5jc3MiLz4KPC9oZWFkPgo8Ym9keT4gICAgCiAgICAKICAgICAgICAgICAgPGRpdiBjbGFzcz0iZm9saXVtLW1hcCIgaWQ9Im1hcF85NDgwM2ViMjk1ZDc0M2VkYTExMzAwNzRlNjdkZGZkYSIgPjwvZGl2PgogICAgICAgIAo8L2JvZHk+CjxzY3JpcHQ+ICAgIAogICAgCiAgICAgICAgICAgIHZhciBtYXBfOTQ4MDNlYjI5NWQ3NDNlZGExMTMwMDc0ZTY3ZGRmZGEgPSBMLm1hcCgKICAgICAgICAgICAgICAgICJtYXBfOTQ4MDNlYjI5NWQ3NDNlZGExMTMwMDc0ZTY3ZGRmZGEiLAogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGNlbnRlcjogWzQwLjAsIC0xMDAuMF0sCiAgICAgICAgICAgICAgICAgICAgY3JzOiBMLkNSUy5FUFNHMzg1NywKICAgICAgICAgICAgICAgICAgICB6b29tOiA0LAogICAgICAgICAgICAgICAgICAgIHpvb21Db250cm9sOiB0cnVlLAogICAgICAgICAgICAgICAgICAgIHByZWZlckNhbnZhczogZmFsc2UsCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICk7CgogICAgICAgICAgICAKCiAgICAgICAgCiAgICAKICAgICAgICAgICAgdmFyIHRpbGVfbGF5ZXJfZDU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gICAgICAgICAgICAgICAgIC5zZXRDb250ZW50KCJMYXRpdHVkZTogIiArIGUubGF0bG5nLmxhdC50b0ZpeGVkKDQpICsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIjxicj5Mb25naXR1ZGU6ICIgKyBlLmxhdGxuZy5sbmcudG9GaXhlZCg0KSkKICAgICAgICAgICAgICAgICAgICAgICAgLm9wZW5PbihtYXBfOTQ4MDNlYjI5NWQ3NDNlZGExMTMwMDc0ZTY3ZGRmZGEpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIG1hcF85NDgwM2ViMjk1ZDc0M2VkYTExMzAwNzRlNjdkZGZkYS5vbignY2xpY2snLCBsYXRMbmdQb3ApOwogICAgICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7f64c0e46e10>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# This function gets NDVI from Landsat 5 imagery.\n",
    "def getNDVI(image):\n",
    "    return image.normalizedDifference(['B4', 'B3'])\n",
    "\n",
    "\n",
    "# Load two Landsat 5 images, 20 years apart.\n",
    "image1 = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_044034_19900604')\n",
    "image2 = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_044034_20100611')\n",
    "\n",
    "# Compute NDVI from the scenes.\n",
    "ndvi1 = getNDVI(image1)\n",
    "ndvi2 = getNDVI(image2)\n",
    "\n",
    "# Compute the difference in NDVI.\n",
    "ndviDifference = ndvi2.subtract(ndvi1)\n",
    "\n",
    "ndviParams = {'palette': ['#d73027', '#f46d43', '#fdae61',\n",
    "                          '#fee08b', '#d9ef8b', '#a6d96a', '#66bd63', '#1a9850']}\n",
    "ndwiParams = {'min': -0.5, 'max': 0.5, 'palette': ['FF0000', 'FFFFFF', '0000FF']}\n",
    "\n",
    "# Create a map\n",
    "Map = folium.Map(location=[40, -100], zoom_start=4)\n",
    "Map.setOptions('HYBRID')\n",
    "\n",
    "Map.centerObject(image1, 10)\n",
    "Map.addLayer(ndvi1, ndviParams, 'NDVI 1')\n",
    "Map.addLayer(ndvi2, ndviParams, 'NDVI 2')\n",
    "Map.addLayer(ndviDifference, ndwiParams, 'NDVI difference')\n",
    "\n",
    "# Diplay the map\n",
    "Map.setControlVisibility()\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "Cn9HVUXciax2"
   },
   "source": [
    "## Mapping (what to do instead of a for-loop)\n",
    "Use `map()` to iterate over items in a collection. (For loops are NOT the right way to do that in Earth Engine and should be avoided). The `map()` function can be applied to an `ImageCollection`, a `FeatureCollection` or a `List` and accepts a function as its argument. The argument of the function is an element of the collection over which it is mapped. This is useful for modifying every element of the collection in the same way, for example adding. For example, the following code adds an NDVI band to every image in an `ImageCollection`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 71
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 16753,
     "status": "ok",
     "timestamp": 1580323493273,
     "user": {
      "displayName": "Qiusheng Wu",
      "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mClnrRJt-9CiCsZmUOfCdngabcoPR4UAFqqj1vY=s64",
      "userId": "16932034244543127511"
     },
     "user_tz": 300
    },
    "id": "RLVSs3XiioJs",
    "outputId": "a3123ce2-1703-4b11-e5e2-e18bb3a3fe3a"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'type': 'Image', 'bands': [{'id': 'B1', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7671, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 463785, 0, -30, 4264515]}, {'id': 'B2', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7671, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 463785, 0, -30, 4264515]}, {'id': 'B3', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7671, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 463785, 0, -30, 4264515]}, {'id': 'B4', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7671, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 463785, 0, -30, 4264515]}, {'id': 'B5', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7671, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 463785, 0, -30, 4264515]}, {'id': 'B6', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7671, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 463785, 0, -30, 4264515]}, {'id': 'B7', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7671, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 463785, 0, -30, 4264515]}, {'id': 'B8', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [15341, 15601], 'crs': 'EPSG:32610', 'crs_transform': [15, 0, 463792.5, 0, -15, 4264507.5]}, {'id': 'B9', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7671, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 463785, 0, -30, 4264515]}, {'id': 'B10', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7671, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 463785, 0, -30, 4264515]}, {'id': 'B11', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7671, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 463785, 0, -30, 4264515]}, {'id': 'BQA', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 65535}, 'dimensions': [7671, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 463785, 0, -30, 4264515]}, {'id': 'nd', 'data_type': {'type': 'PixelType', 'precision': 'float', 'min': -1, 'max': 1}, 'dimensions': [7671, 7801], 'crs': 'EPSG:32610', 'crs_transform': [30, 0, 463785, 0, -30, 4264515]}], 'id': 'LANDSAT/LC08/C01/T1/LC08_044034_20140606', 'version': 1497493928601000.0, 'properties': {'RADIANCE_MULT_BAND_5': 0.005937200039625168, 'RADIANCE_MULT_BAND_6': 0.0014764999505132437, 'RADIANCE_MULT_BAND_3': 0.011505999602377415, 'RADIANCE_MULT_BAND_4': 0.009702100418508053, 'RADIANCE_MULT_BAND_1': 0.012192999944090843, 'RADIANCE_MULT_BAND_2': 0.01248599961400032, 'K2_CONSTANT_BAND_11': 1201.1441650390625, 'K2_CONSTANT_BAND_10': 1321.078857421875, 'system:footprint': {'type': 'LinearRing', 'coordinates': [[-120.79200539048736, 38.12706906512293], [-120.79323597868374, 38.12758439698958], [-120.82683301978153, 38.13425518072935], [-122.57369124774934, 38.465867462644404], [-122.91132538951987, 38.52663370240754], [-122.91414613702007, 38.526635850439405], [-122.9189327723941, 38.510718361283075], [-123.40419439796977, 36.80678576741027], [-121.36227701906473, 36.41476296352091], [-121.32989516455781, 36.40824848906167], [-121.20432618246714, 36.815494543804164], [-121.07428782575109, 37.232255532839595], [-120.95966651326353, 37.59672218968956], [-120.90596782826022, 37.76651090203559], [-120.86494805861443, 37.895947164272634], [-120.83393920808882, 37.993514542680224], [-120.82433446488996, 38.02375043851124], [-120.79204501354904, 38.125755061557996], [-120.79200539048736, 38.12706906512293]]}, 'REFLECTIVE_SAMPLES': 7671, 'SUN_AZIMUTH': 124.43635559082031, 'CPF_NAME': 'LC08CPF_20140401_20140630_01.01', 'DATE_ACQUIRED': '2014-06-06', 'ELLIPSOID': 'WGS84', 'google:registration_offset_x': 0, 'google:registration_offset_y': 0, 'STATION_ID': 'LGN', 'RESAMPLING_OPTION': 'CUBIC_CONVOLUTION', 'ORIENTATION': 'NORTH_UP', 'WRS_ROW': 34, 'RADIANCE_MULT_BAND_9': 0.002320399973541498, 'TARGET_WRS_ROW': 34, 'RADIANCE_MULT_BAND_7': 0.0004976699710823596, 'RADIANCE_MULT_BAND_8': 0.010979999788105488, 'IMAGE_QUALITY_TIRS': 9, 'TRUNCATION_OLI': 'UPPER', 'CLOUD_COVER': 35.709999084472656, 'GEOMETRIC_RMSE_VERIFY': 2.7200000286102295, 'COLLECTION_CATEGORY': 'T1', 'GRID_CELL_SIZE_REFLECTIVE': 30, 'CLOUD_COVER_LAND': 3.930000066757202, 'GEOMETRIC_RMSE_MODEL': 5.419000148773193, 'COLLECTION_NUMBER': 1, 'IMAGE_QUALITY_OLI': 9, 'LANDSAT_SCENE_ID': 'LC80440342014157LGN01', 'WRS_PATH': 44, 'google:registration_count': 0, 'PANCHROMATIC_SAMPLES': 15341, 'PANCHROMATIC_LINES': 15601, 'GEOMETRIC_RMSE_MODEL_Y': 3.4519999027252197, 'REFLECTIVE_LINES': 7801, 'TIRS_STRAY_LIGHT_CORRECTION_SOURCE': 'TIRS', 'GEOMETRIC_RMSE_MODEL_X': 4.177000045776367, 'system:asset_size': 1264461529, 'system:index': 'LC08_044034_20140606', 'REFLECTANCE_ADD_BAND_1': -0.10000000149011612, 'REFLECTANCE_ADD_BAND_2': -0.10000000149011612, 'DATUM': 'WGS84', 'REFLECTANCE_ADD_BAND_3': -0.10000000149011612, 'REFLECTANCE_ADD_BAND_4': -0.10000000149011612, 'RLUT_FILE_NAME': 'LC08RLUT_20130211_20150302_01_11.h5', 'REFLECTANCE_ADD_BAND_5': -0.10000000149011612, 'REFLECTANCE_ADD_BAND_6': -0.10000000149011612, 'REFLECTANCE_ADD_BAND_7': -0.10000000149011612, 'REFLECTANCE_ADD_BAND_8': -0.10000000149011612, 'BPF_NAME_TIRS': 'LT8BPF20140606181212_20140606190417.01', 'GROUND_CONTROL_POINTS_VERSION': 4, 'DATA_TYPE': 'L1TP', 'UTM_ZONE': 10, 'LANDSAT_PRODUCT_ID': 'LC08_L1TP_044034_20140606_20170305_01_T1', 'REFLECTANCE_ADD_BAND_9': -0.10000000149011612, 'google:registration_ratio': 0, 'GRID_CELL_SIZE_PANCHROMATIC': 15, 'RADIANCE_ADD_BAND_4': -48.51054000854492, 'REFLECTANCE_MULT_BAND_7': 1.9999999494757503e-05, 'system:time_start': 1402080344240, 'RADIANCE_ADD_BAND_5': -29.6860294342041, 'REFLECTANCE_MULT_BAND_6': 1.9999999494757503e-05, 'RADIANCE_ADD_BAND_6': -7.382649898529053, 'REFLECTANCE_MULT_BAND_9': 1.9999999494757503e-05, 'PROCESSING_SOFTWARE_VERSION': 'LPGS_2.7.0', 'RADIANCE_ADD_BAND_7': -2.4883499145507812, 'REFLECTANCE_MULT_BAND_8': 1.9999999494757503e-05, 'RADIANCE_ADD_BAND_1': -60.96493148803711, 'RADIANCE_ADD_BAND_2': -62.428829193115234, 'RADIANCE_ADD_BAND_3': -57.52762985229492, 'REFLECTANCE_MULT_BAND_1': 1.9999999494757503e-05, 'RADIANCE_ADD_BAND_8': -54.90058135986328, 'REFLECTANCE_MULT_BAND_3': 1.9999999494757503e-05, 'RADIANCE_ADD_BAND_9': -11.601969718933105, 'REFLECTANCE_MULT_BAND_2': 1.9999999494757503e-05, 'REFLECTANCE_MULT_BAND_5': 1.9999999494757503e-05, 'REFLECTANCE_MULT_BAND_4': 1.9999999494757503e-05, 'THERMAL_LINES': 7801, 'TIRS_SSM_POSITION_STATUS': 'NOMINAL', 'GRID_CELL_SIZE_THERMAL': 30, 'NADIR_OFFNADIR': 'NADIR', 'RADIANCE_ADD_BAND_11': 0.10000000149011612, 'REQUEST_ID': '0501703043447_00036', 'EARTH_SUN_DISTANCE': 1.014767050743103, 'TIRS_SSM_MODEL': 'ACTUAL', 'FILE_DATE': 1488689158000, 'SCENE_CENTER_TIME': '18:45:44.2439160Z', 'SUN_ELEVATION': 67.10252380371094, 'BPF_NAME_OLI': 'LO8BPF20140606171321_20140606190324.01', 'RADIANCE_ADD_BAND_10': 0.10000000149011612, 'ROLL_ANGLE': -0.0010000000474974513, 'K1_CONSTANT_BAND_10': 774.8853149414062, 'SATURATION_BAND_1': 'Y', 'SATURATION_BAND_2': 'Y', 'SATURATION_BAND_3': 'Y', 'SATURATION_BAND_4': 'Y', 'SATURATION_BAND_5': 'Y', 'MAP_PROJECTION': 'UTM', 'SATURATION_BAND_6': 'Y', 'SENSOR_ID': 'OLI_TIRS', 'SATURATION_BAND_7': 'Y', 'K1_CONSTANT_BAND_11': 480.8883056640625, 'SATURATION_BAND_8': 'N', 'SATURATION_BAND_9': 'N', 'TARGET_WRS_PATH': 44, 'RADIANCE_MULT_BAND_11': 0.00033420001273043454, 'RADIANCE_MULT_BAND_10': 0.00033420001273043454, 'GROUND_CONTROL_POINTS_MODEL': 549, 'SPACECRAFT_ID': 'LANDSAT_8', 'ELEVATION_SOURCE': 'GLS2000', 'THERMAL_SAMPLES': 7671, 'GROUND_CONTROL_POINTS_VERIFY': 192}}\n",
      "['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'B10', 'B11', 'BQA', 'nd']\n"
     ]
    }
   ],
   "source": [
    "# This function gets NDVI from Landsat 8 imagery.\n",
    "\n",
    "def addNDVI(image):\n",
    "    return image.addBands(image.normalizedDifference(['B5', 'B4']))\n",
    "\n",
    "# Load the Landsat 8 raw data, filter by location and date.\n",
    "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1') \\\n",
    "    .filterBounds(ee.Geometry.Point(-122.262, 37.8719)) \\\n",
    "    .filterDate('2014-06-01', '2014-10-01')\n",
    "\n",
    "# Map the function over the collection.\n",
    "ndviCollection = collection.map(addNDVI)\n",
    "\n",
    "first = ndviCollection.first()\n",
    "print(first.getInfo())\n",
    "\n",
    "bandNames = first.bandNames()\n",
    "print(bandNames.getInfo())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "YVcHb4TcjgHN"
   },
   "source": [
    "## Reducing\n",
    "Reducing is the way to aggregate data over time, space, bands, arrays and other data structures in Earth Engine. Various methods exist for this purpose in the API. For example, to make a composite of an `ImageCollection`, use `reduce()` to reduce the images in the collection to one Image. A simple example is creating the median composite of the five least cloudy scenes in the Landsat 8 collection defined earlier:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 907
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 17192,
     "status": "ok",
     "timestamp": 1580323493724,
     "user": {
      "displayName": "Qiusheng Wu",
      "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mClnrRJt-9CiCsZmUOfCdngabcoPR4UAFqqj1vY=s64",
      "userId": "16932034244543127511"
     },
     "user_tz": 300
    },
    "id": "SNfKnvq5jnTy",
    "outputId": "13fda25d-30ce-4323-c031-f086531c3698"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgCiAgICAgICAgPHNjcmlwdD4KICAgICAgICAgICAgTF9OT19UT1VDSCA9IGZhbHNlOwogICAgICAgICAgICBMX0RJU0FCTEVfM0QgPSBmYWxzZTsKICAgICAgICA8L3NjcmlwdD4KICAgIAogICAgPHNjcmlwdCBzcmM9Imh0dHBzOi8vY2RuLmpz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iNDY4MTgxYmVkMjBlNjc3YTkyYTEgPSB7CiAgICAgICAgICAgICAgICBiYXNlX2xheWVycyA6IHsKICAgICAgICAgICAgICAgICAgICAib3BlbnN0cmVldG1hcCIgOiB0aWxlX2xheWVyXzJkZWEwYjUzZWQ1MDQ0OWFhZmE4N2QwYzRiOTg1MjZkLAogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgIG92ZXJsYXlzIDogIHsKICAgICAgICAgICAgICAgICAgICAiR29vZ2xlIFNhdGVsbGl0ZSIgOiB0aWxlX2xheWVyX2EzOGJiODQ3ZTBiNzRlZjI4OTZkMDliY2M0ZjY3N2MzLAogICAgICAgICAgICAgICAgICAgICJNZWRpYW4gaW1hZ2UiIDogdGlsZV9sYXllcl8yZmYzMGMyZDllZTg0YjcyODRiNTY3MzdmMzhiODViOSwKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgIH07CiAgICAgICAgICAgIEwuY29udHJvbC5sYXllcnMoCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sXzA4MjZkMjg2NzI4YjQ2ODE4MWJlZDIwZTY3N2E5MmExLmJhc2VfbGF5ZXJzLAogICAgICAgICAgICAgICAgbGF5ZXJfY29udHJvbF8wODI2ZDI4NjcyOGI0NjgxODFiZWQyMGU2NzdhOTJhMS5vdmVybGF5cywKICAgICAgICAgICAgICAgIHsiYXV0b1pJbmRleCI6IHRydWUsICJjb2xsYXBzZWQiOiB0cnVlLCAicG9zaXRpb24iOiAidG9wcmlnaHQifQogICAgICAgICAgICApLmFkZFRvKG1hcF8wYTJmN2QxYjJkZTU0YTljYTUwZDYzZTM5N2JlYzg3Yyk7CiAgICAgICAgCiAgICAKICAgICAgICAgICAgTC5jb250cm9sLmZ1bGxzY3JlZW4oCiAgICAgICAgICAgICAgICB7ImZvcmNlU2VwYXJhdGVCdXR0b24iOiBmYWxzZSwgInBvc2l0aW9uIjogInRvcGxlZnQiLCAidGl0bGUiOiAiRnVsbCBTY3JlZW4iLCAidGl0bGVDYW5jZWwiOiAiRXhpdCBGdWxsIFNjcmVlbiJ9CiAgICAgICAgICAgICkuYWRkVG8obWFwXzBhMmY3ZDFiMmRlNTRhOWNhNTBkNjNlMzk3YmVjODdjKTsKICAgICAgICAKICAgIAogICAgICAgICAgICAgICAgdmFyIGxhdF9sbmdfcG9wdXBfZTU1OTVkZDM2MDdkNGVmNTk3NTM3MTQyMTE1OGZlMDkgPSBMLnBvcHVwKCk7CiAgICAgICAgICAgICAgICBmdW5jdGlvbiBsYXRMbmdQb3AoZSkgewogICAgICAgICAgICAgICAgICAgIGxhdF9sbmdfcG9wdXBfZTU1OTVkZDM2MDdkNGVmNTk3NTM3MTQyMTE1OGZlMDkKICAgICAgICAgICAgICAgICAgICAgICAgLnNldExhdExuZyhlLmxhdGxuZykKICAgICAgICAgICAgICAgICAgICAgICAgLnNldENvbnRlbnQoIkxhdGl0dWRlOiAiICsgZS5sYXRsbmcubGF0LnRvRml4ZWQoNCkgKwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiPGJyPkxvbmdpdHVkZTogIiArIGUubGF0bG5nLmxuZy50b0ZpeGVkKDQpKQogICAgICAgICAgICAgICAgICAgICAgICAub3Blbk9uKG1hcF8wYTJmN2QxYjJkZTU0YTljYTUwZDYzZTM5N2JlYzg3Yyk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgbWFwXzBhMmY3ZDFiMmRlNTRhOWNhNTBkNjNlMzk3YmVjODdjLm9uKCdjbGljaycsIGxhdExuZ1BvcCk7CiAgICAgICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7f64c0e916d8>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Load a Landsat 8 collection.\n",
    "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1') \\\n",
    "    .filterBounds(ee.Geometry.Point(-122.262, 37.8719)) \\\n",
    "    .filterDate('2014-01-01', '2014-12-31') \\\n",
    "    .sort('CLOUD_COVER')\n",
    "\n",
    "# Compute the median of each pixel for each band of the 5 least cloudy scenes.\n",
    "median = collection.limit(5).reduce(ee.Reducer.median())\n",
    "\n",
    "# Define visualization parameters in an object literal.\n",
    "vizParams = {'bands': ['B5_median', 'B4_median', 'B3_median'],\n",
    "             'min': 5000, 'max': 15000, 'gamma': 1.3}\n",
    "\n",
    "Map = folium.Map()\n",
    "Map.setOptions('HYBRID')\n",
    "Map.setCenter(-122.262, 37.8719, 10)\n",
    "Map.addLayer(median, vizParams, 'Median image')\n",
    "Map.setControlVisibility()\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "k2ZtKiyuko62"
   },
   "source": [
    "Reducing is also the way to get statistics of an image in the regions defined by a `Feature` or `FeatureCollection`. Suppose the task is to compute the mean pixel values within an area of interest. Use `reduceRegion()` for this purpose. For example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 18758,
     "status": "ok",
     "timestamp": 1580323495301,
     "user": {
      "displayName": "Qiusheng Wu",
      "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mClnrRJt-9CiCsZmUOfCdngabcoPR4UAFqqj1vY=s64",
      "userId": "16932034244543127511"
     },
     "user_tz": 300
    },
    "id": "2IaNU0BIkv_v",
    "outputId": "d1519f48-5eb4-4891-e1d3-93f904bd17cf"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('B1', 0.10156726419256697)\n",
      "('B10', 288.3898316688731)\n",
      "('B11', 287.4496961587173)\n",
      "('B2', 0.07771978773589312)\n",
      "('B3', 0.05530074222374056)\n",
      "('B4', 0.03670883505442356)\n",
      "('B5', 0.22139764553479283)\n",
      "('B6', 0.07888235294207073)\n",
      "('B7', 0.035089536963059234)\n",
      "('B8', 0.047100656968120116)\n",
      "('B9', 0.00156092084691453)\n",
      "('BQA', 2720.11945357173)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgCiAgICAgICAgPHNjcmlwdD4KICAgICAgICAgICAgTF9OT19UT1VDSCA9IGZhbHNlOwogICAgICAgICAgICBMX0RJU0FCTEVfM0QgPSBmYWxzZTsKICAgICAgICA8L3NjcmlwdD4KICAgIAogICAgPHNjcmlwdCBzcmM9Imh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vbGVhZmxldEAxLjUuMS9kaXN0L2xlYWZsZXQuanMiPjwvc2NyaXB0PgogICAgPHNjcmlwdCBzcmM9Imh0dHBzOi8vY29kZS5qcXVlcnkuY29tL2pxdWVyeS0xLjEyLjQubWluLmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL21heGNkbi5ib290c3RyYXBjZG4uY29tL2Jvb3RzdHJhcC8zLjIuMC9qcy9ib290c3RyYXAubWluLmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NkbmpzLmNsb3VkZmxhcmUuY29tL2FqYXgvbGlicy9MZWFmbGV0LmF3ZXNvbWUtbWFya2Vycy8yLjAuMi9sZWFmbGV0LmF3ZXNvbWUtbWFya2Vycy5qcyI+PC9zY3JpcHQ+CiAgICA8bGluayByZWw9InN0eWxlc2hlZXQiIGhyZWY9Imh0dHBzOi8vY2RuLmpzZGVsaX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IHZhciBtYXBfZTFmN2JmYWI4MTQ4NDRhMThjYzYzMGFlNWI1MTk0YjMgPSBMLm1hcCgKICAgICAgICAgICAgICAgICJtYXBfZTFmN2JmYWI4MTQ4NDRhMThjYzYzMGFlNWI1MTk0YjMiLAogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGNlbnRlcjogWzAsIDBdLAogICAgICAgICAgICAgICAgICAgIGNyczogTC5DUlMuRVBTRzM4NTcsCiAgICAgICAgICAgICAgICAgICAgem9vbTogMSwKICAgICAgICAgICAgICAgICAgICB6b29tQ29udHJvbDogdHJ1ZSwKICAgICAgICAgICAgICAgICAgICBwcmVmZXJDYW52YXM6IGZhbHNlLAogICAgICAgICAgICAgICAgfQogICAgICAgICAgICApOwoKICAgICAgICAgICAgCgogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciB0aWxlX2xheWVyX2MwNmZkYmY0OWU4YzRkYjM4YjA5ZTFlNWFjNGRmZmZiID0gTC50aWxlTGF5ZXIoCiAgICAgICAgICAgICAgICAiaHR0cHM6Ly97c30udGlsZS5vcGVuc3RyZWV0bWFwLm9yZy97en0ve3h9L3t5fS5wbmciLAogICAgICAgICAgICAgICAgeyJhdHRyaWJ1dGlvbiI6ICJEYXRhIGJ5IFx1MDAyNmNvcHk7IFx1MDAzY2EgaHJlZj1cImh0dHA6Ly9vcGVuc3RyZWV0bWFwLm9yZ1wiXHUwMDNlT3BlblN0cmVldE1hcFx1MDAzYy9hXHUwMDNlLCB1bmRlciBcdTAwM2NhIGhyZWY9XCJodHRwOi8vd3d3Lm9wZW5zdHJlZXRtYXAub3JnL2NvcHlyaWdodFwiXHUwMDNlT0RiTFx1MDAzYy9hXHUwMDNlLiIsICJkZXRlY3RSZXRpbmEiOiBmYWxzZSwgIm1heE5hdGl2ZVpvb20iOiAxOCwgIm1heFpvb20iOiAxOCwgIm1pblpvb20iOiAwLCAibm9XcmFwIjogZmFsc2UsICJvcGFjaXR5IjogMSwgInN1YmRvbWFpbn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iOiB0cnVlLCAicG9zaXRpb24iOiAidG9wcmlnaHQifQogICAgICAgICAgICApLmFkZFRvKG1hcF9lMWY3YmZhYjgxNDg0NGExOGNjNjMwYWU1YjUxOTRiMyk7CiAgICAgICAgCiAgICAKICAgICAgICAgICAgTC5jb250cm9sLmZ1bGxzY3JlZW4oCiAgICAgICAgICAgICAgICB7ImZvcmNlU2VwYXJhdGVCdXR0b24iOiBmYWxzZSwgInBvc2l0aW9uIjogInRvcGxlZnQiLCAidGl0bGUiOiAiRnVsbCBTY3JlZW4iLCAidGl0bGVDYW5jZWwiOiAiRXhpdCBGdWxsIFNjcmVlbiJ9CiAgICAgICAgICAgICkuYWRkVG8obWFwX2UxZjdiZmFiODE0ODQ0YTE4Y2M2MzBhZTViNTE5NGIzKTsKICAgICAgICAKICAgIAogICAgICAgICAgICAgICAgdmFyIGxhdF9sbmdfcG9wdXBfMTQ5YTVjYTY5NjU3NDFhODg0M2Y5ZDQ0NGZkODcwYTAgPSBMLnBvcHVwKCk7CiAgICAgICAgICAgICAgICBmdW5jdGlvbiBsYXRMbmdQb3AoZSkgewogICAgICAgICAgICAgICAgICAgIGxhdF9sbmdfcG9wdXBfMTQ5YTVjYTY5NjU3NDFhODg0M2Y5ZDQ0NGZkODcwYTAKICAgICAgICAgICAgICAgICAgICAgICAgLnNldExhdExuZyhlLmxhdGxuZykKICAgICAgICAgICAgICAgICAgICAgICAgLnNldENvbnRlbnQoIkxhdGl0dWRlOiAiICsgZS5sYXRsbmcubGF0LnRvRml4ZWQoNCkgKwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiPGJyPkxvbmdpdHVkZTogIiArIGUubGF0bG5nLmxuZy50b0ZpeGVkKDQpKQogICAgICAgICAgICAgICAgICAgICAgICAub3Blbk9uKG1hcF9lMWY3YmZhYjgxNDg0NGExOGNjNjMwYWU1YjUxOTRiMyk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgbWFwX2UxZjdiZmFiODE0ODQ0YTE4Y2M2MzBhZTViNTE5NGIzLm9uKCdjbGljaycsIGxhdExuZ1BvcCk7CiAgICAgICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7f64c0da4198>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create a map\n",
    "Map = folium.Map()\n",
    "Map.setOptions('HYBRID')\n",
    "\n",
    "# Load and display a Landsat TOA image.\n",
    "image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')\n",
    "Map.addLayer(image, {'bands': ['B4', 'B3', 'B2'], max: 0.3}, 'Landsat 8')\n",
    "\n",
    "# // Create an arbitrary rectangle as a region and display it.\n",
    "region = ee.Geometry.Rectangle(-122.2806, 37.1209, -122.0554, 37.2413)\n",
    "Map.centerObject(region, 10)\n",
    "Map.addLayer(region, {}, 'ROI')\n",
    "\n",
    "# // Get a dictionary of means in the region.  Keys are bandnames.\n",
    "mean = image.reduceRegion(**{\n",
    "  'reducer': ee.Reducer.mean(),\n",
    "  'geometry': region,\n",
    "  'scale': 30\n",
    "})\n",
    "\n",
    "results = mean.getInfo()\n",
    "for item in results.items():\n",
    "  print(item)\n",
    "\n",
    "Map.setControlVisibility()\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "lICQJguDmpWo"
   },
   "source": [
    "## Masking\n",
    "Every pixel in an `ee.Image` has both a value and a mask which ranges from 0 (no data) to 1. Masked pixels (in which mask==0) are treated as no data. Pixels with 0 < mask ≤ 1 have a value, but it is weighted by the mask for numerical computations.\n",
    "\n",
    "You can make pixels transparent or exclude them from analysis using masks. Pixels are masked when the mask value is zero. Continuing the image differencing example, use a mask to display areas of increased and decreased NDVI over the difference interval:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 907
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 1657,
     "status": "ok",
     "timestamp": 1580323942782,
     "user": {
      "displayName": "Qiusheng Wu",
      "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mClnrRJt-9CiCsZmUOfCdngabcoPR4UAFqqj1vY=s64",
      "userId": "16932034244543127511"
     },
     "user_tz": 300
    },
    "id": "kbhCVgZAmu38",
    "outputId": "9df38b8e-30b7-49eb-ad39-e5755bce3a77"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgCiAgICAgICAgPHNjcmlwdD4KICAgICAgICAgICAgTF9OT19UT1VDSCA9IGZhbHNlOwogICAgICAgICAgICBMX0RJU0FCTEVfM0QgPSBmYWxzZTsKICAgICAgICA8L3NjcmlwdD4KICAgIAogICAgPHNjcmlwdCBzcmM9Imh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vbGVhZmxldEAxLjUuMS9kaXN0L2xlYWZsZXQuanMiPjwvc2NyaXB0PgogICAgPHNjcmlwdCBzcmM9Imh0dHBzOi8vY29kZS5qcXVlcnkuY29tL2pxdWVyeS0xLjEyLjQubWluLmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL21heGNkbi5ib290c3RyYXBjZG4uY29tL2Jvb3RzdHJhcC8zLjIuMC9qcy9ib290c3RyYXAubWluLmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2NkbmpzLmNsb3VkZmxhcmUuY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gCiAgICAKICAgICAgICAgICAgPGRpdiBjbGFzcz0iZm9saXVtLW1hcCIgaWQ9Im1hcF9kZGY3M2I0Y2ZjODI0MGJiODUyMDU0YWE1OGM3NGYwMSIgPjwvZGl2PgogICAgICAgIAo8L2JvZHk+CjxzY3JpcHQ+ICAgIAogICAgCiAgICAgICAgICAgIHZhciBtYXBfZGRmNzNiNGNmYzgyNDBiYjg1MjA1NGFhNThjNzRmMDEgPSBMLm1hcCgKICAgICAgICAgICAgICAgICJtYXBfZGRmNzNiNGNmYzgyNDBiYjg1MjA1NGFhNThjNzRmMDEiLAogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGNlbnRlcjogWzAsIDBdLAogICAgICAgICAgICAgICAgICAgIGNyczogTC5DUlMuRVBTRzM4NTcsCiAgICAgICAgICAgICAgICAgICAgem9vbTogMSwKICAgICAgICAgICAgICAgICAgICB6b29tQ29udHJvbDogdHJ1ZSwKICAgICAgICAgICAgICAgICAgICBwcmVmZXJDYW52YXM6IGZhbHNlLAogICAgICAgICAgICAgICAgfQogICAgICAgICAgICApOwoKICAgICAgICAgICAgCgogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciB0aWxlX2xheWVyX2M0ZDQ2ZDgzMGNlMjQwMGU5NDY2NTU1ZWIxMWE0MGYyID0gTC50aWxlTGF5ZXIoCiAgICAgICAgICAgICAgICAiaHR0cHM6Ly97c30udGlsZS5vcGVuc3RyZWV0bWFwLm9yZy97en0ve3h9L3t5fS5wbmciLAogICAgICAgICAgICAgICAgeyJhdHRyaWJ1dGlvbiI6ICJEYXRhIGJ5IFx1MDAyNmNvcHk7IFx1MDAzY2EgaHJlZj1cImh0dHA6Ly9vcGVuc3RyZWV0bWFwLm9yZ1wiXHUwMDNlT3BlblN0cmVldE1hcFx1MDAzYy9hXHUwMDNlLCB1bmRlciBcdTAwM2NhIGhyZWY9XCJodHRwOi8vd3d3Lm9wZW5zdHJlZXRtYXAub3JnL2NvcHlyaWdodFwiXHUwM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hdGl0dWRlOiAiICsgZS5sYXRsbmcubGF0LnRvRml4ZWQoNCkgKwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiPGJyPkxvbmdpdHVkZTogIiArIGUubGF0bG5nLmxuZy50b0ZpeGVkKDQpKQogICAgICAgICAgICAgICAgICAgICAgICAub3Blbk9uKG1hcF9kZGY3M2I0Y2ZjODI0MGJiODUyMDU0YWE1OGM3NGYwMSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgbWFwX2RkZjczYjRjZmM4MjQwYmI4NTIwNTRhYTU4Yzc0ZjAxLm9uKCdjbGljaycsIGxhdExuZ1BvcCk7CiAgICAgICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7f64c0e46e80>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# This function gets NDVI from Landsat 5 imagery.\n",
    "def getNDVI(image):\n",
    "    return image.normalizedDifference(['B4', 'B3'])\n",
    "\n",
    "# Load two Landsat 5 images, 20 years apart.\n",
    "image1 = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_044034_19900604')\n",
    "image2 = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_044034_20100611')\n",
    "\n",
    "# Compute NDVI from the scenes.\n",
    "ndvi1 = getNDVI(image1)\n",
    "ndvi2 = getNDVI(image2)\n",
    "\n",
    "# Compute the difference in NDVI.\n",
    "ndviDifference = ndvi2.subtract(ndvi1)\n",
    "# Load the land mask from the SRTM DEM.\n",
    "landMask = ee.Image('CGIAR/SRTM90_V4').mask()\n",
    "\n",
    "# Update the NDVI difference mask with the land mask.\n",
    "maskedDifference = ndviDifference.updateMask(landMask)\n",
    "\n",
    "# Display the masked result.\n",
    "vizParams = {'min': -0.5, 'max': 0.5,\n",
    "             'palette': ['FF0000', 'FFFFFF', '0000FF']}\n",
    "\n",
    "Map = folium.Map()\n",
    "Map.setOptions('HYBRID')\n",
    "Map.setCenter(-122.2531, 37.6295, 9)\n",
    "Map.addLayer(ndviDifference, vizParams, 'NDVI difference without mask', False)\n",
    "Map.addLayer(maskedDifference, vizParams, 'NDVI difference with mask')\n",
    "Map.setControlVisibility()\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "SeksLqnspaqs"
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "zBGSftcWpd_B"
   },
   "source": [
    "## A complete example\n",
    "The following example demonstrates multiple concepts: filtering, mapping, reducing and the use of a cloud mask:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 924
    },
    "colab_type": "code",
    "executionInfo": {
     "elapsed": 17435,
     "status": "ok",
     "timestamp": 1580324797984,
     "user": {
      "displayName": "Qiusheng Wu",
      "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mClnrRJt-9CiCsZmUOfCdngabcoPR4UAFqqj1vY=s64",
      "userId": "16932034244543127511"
     },
     "user_tz": 300
    },
    "id": "5XTjFMZhpljf",
    "outputId": "3be2f9df-6c12-410a-cbe5-c3cfd34cad2d"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Santa Clara spring mean NDVI: 0.46507494635226865\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiA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U7CiAgICAgICAgICAgICAgICAgICAgaGVpZ2h0OiAxMDAuMCU7CiAgICAgICAgICAgICAgICAgICAgbGVmdDogMC4wJTsKICAgICAgICAgICAgICAgICAgICB0b3A6IDAuMCU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIDwvc3R5bGU+CiAgICAgICAgCiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvbGVhZmxldC5mdWxsc2NyZWVuLzEuNC4yL0NvbnRyb2wuRnVsbFNjcmVlbi5taW4uanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2NkbmpzLmNsb3VkZmxhcmUuY29tL2FqYXgvbGlicy9sZWFmbGV0LmZ1bGxzY3JlZW4vMS40LjIvQ29udHJvbC5GdWxsU2NyZWVuLm1pbi5jc3MiLz4KPC9oZWFkPgo8Ym9keT4gICAgCiAgICAKICAgICAgICAgICAgPGRpdiBjbGFzcz0iZm9saXVtLW1hcCIgaWQ9Im1hcF8zMTVhNmY1ZTQ5NWE0ZmRmOTBlMmU3ODNkODVmYmRhMyIgPjwvZGl2PgogICAgICAgIAo8L2JvZHk+CjxzY3JpcHQ+ICAgIAogICAgCiAgICAgICAgICAgIHZhciBtYXBfMzE1YTZmNWU0OTVhNGZkZjkwZTJlNzgzZDg1ZmJkYTMgPSBMLm1hcCgKICAgICAgICAgICAgICAgICJtYXBfMzE1YTZmNWU0OTVhNGZkZjkwZTJlNzgzZDg1ZmJkYTMiLAogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGNlbnRlcjogWzAsIDBdLAogICAgICAgICAgICAgICAgICAgIGNyczogTC5DUlMuRVBTRzM4NTcsCiAgICAgICAgICAgICAgICAgICAgem9vbTogMSwKICAgICAgICAgICAgICAgICAgICB6b29tQ29udHJvbDogdHJ1ZSwKICAgICAgICAgICAgICAgICAgICBwcmVmZXJ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k1YTRmZGY5MGUyZTc4M2Q4NWZiZGEzKTsKICAgICAgICAKICAgIAogICAgICAgICAgICAgICAgdmFyIGxhdF9sbmdfcG9wdXBfYTZkY2VjOTE5NWE3NDQwZGI4YWZmYzY2NjgyNWE1YmMgPSBMLnBvcHVwKCk7CiAgICAgICAgICAgICAgICBmdW5jdGlvbiBsYXRMbmdQb3AoZSkgewogICAgICAgICAgICAgICAgICAgIGxhdF9sbmdfcG9wdXBfYTZkY2VjOTE5NWE3NDQwZGI4YWZmYzY2NjgyNWE1YmMKICAgICAgICAgICAgICAgICAgICAgICAgLnNldExhdExuZyhlLmxhdGxuZykKICAgICAgICAgICAgICAgICAgICAgICAgLnNldENvbnRlbnQoIkxhdGl0dWRlOiAiICsgZS5sYXRsbmcubGF0LnRvRml4ZWQoNCkgKwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiPGJyPkxvbmdpdHVkZTogIiArIGUubGF0bG5nLmxuZy50b0ZpeGVkKDQpKQogICAgICAgICAgICAgICAgICAgICAgICAub3Blbk9uKG1hcF8zMTVhNmY1ZTQ5NWE0ZmRmOTBlMmU3ODNkODVmYmRhMyk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgbWFwXzMxNWE2ZjVlNDk1YTRmZGY5MGUyZTc4M2Q4NWZiZGEzLm9uKCdjbGljaycsIGxhdExuZ1BvcCk7CiAgICAgICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7f64c0e46978>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# This function gets NDVI from a Landsat 8 image.\n",
    "\n",
    "def addNDVI(image):\n",
    "    return image.addBands(image.normalizedDifference(['B5', 'B4']))\n",
    "\n",
    "# This function masks cloudy pixels.\n",
    "\n",
    "\n",
    "def cloudMask(image):\n",
    "    clouds = ee.Algorithms.Landsat.simpleCloudScore(image).select(['cloud'])\n",
    "    return image.updateMask(clouds.lt(10))\n",
    "\n",
    "# Create a map\n",
    "Map = folium.Map()\n",
    "Map.setOptions('HYBRID')\n",
    "\n",
    "# Load a Landsat collection, map the NDVI and cloud masking functions over it.\n",
    "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA') \\\n",
    "    .filterBounds(ee.Geometry.Point([-122.262, 37.8719])) \\\n",
    "    .filterDate('2014-03-01', '2014-05-31') \\\n",
    "    .map(addNDVI) \\\n",
    "    .map(cloudMask)\n",
    "\n",
    "# Reduce the collection to the mean of each pixel and display.\n",
    "meanImage = collection.reduce(ee.Reducer.mean())\n",
    "vizParams = {'bands': ['B5_mean', 'B4_mean', 'B3_mean'], 'min': 0, 'max': 0.5}\n",
    "Map.setCenter(-122.262, 37.8719, 10)\n",
    "Map.addLayer(meanImage, vizParams, 'mean')\n",
    "\n",
    "# Load a region in which to compute the mean and display it.\n",
    "counties = ee.FeatureCollection('TIGER/2016/Counties')\n",
    "santaClara = ee.Feature(counties.filter(\n",
    "    ee.Filter.eq('NAME', 'Santa Clara')).first())\n",
    "Map.addLayer(ee.Image().paint(santaClara, 0, 2), {\n",
    "             'palette': 'yellow'}, 'Santa Clara')\n",
    "\n",
    "# Get the mean of NDVI in the region.\n",
    "mean = meanImage.select(['nd_mean']).reduceRegion(**{\n",
    "    'reducer': ee.Reducer.mean(),\n",
    "    'geometry': santaClara.geometry(),\n",
    "    'scale': 30\n",
    "})\n",
    "\n",
    "# Print mean NDVI for the region.\n",
    "print('Santa Clara spring mean NDVI:', mean.get('nd_mean').getInfo())\n",
    "\n",
    "Map.setControlVisibility()\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "JOHuqUzasnl-"
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "authorship_tag": "ABX9TyMdf8PCtjymtVbzvzulR1Jt",
   "collapsed_sections": [],
   "name": "10_Get_Started_with_EE.ipynb",
   "provenance": [],
   "toc_visible": true
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
